<?php

namespace app\common\model;

class Express extends Base
{
    // 设置当前模型对应的完整数据表名称
    protected $table = 'ddt_express';
    // 主键ID
    protected $pk = 'express_id';



    /**
     * @param array $where  // 查询的条件
     * @param string $item  // 查询的参数
     * @return array
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    function getOne($where=[1], $item='*')
    {
        $rs = $this
            ->field($item)
            ->where($where)
            ->find();

        return $rs;
    }
    

    // 获取分页列表
    function get_list_page($cond,$orderby,$item,$limit)
    {
        $where = null;
        if(!empty($cond['express_name'])){
            $where[] = ['express_name','like',"%".$cond['express_name']."%"];
        }

        if(!empty($cond['status'])){
            $where[] = ['status', '=',$cond['status']];
        }
        $rs = $this
            ->field($item)
            ->where($where)
            ->order($orderby)
            ->paginate($limit);

        return $rs;
    }


    // 获取列表
    function get_list($cond,$orderby,$item,$page=1,$limit=0)
    {
        $where = null;

        if(!empty($cond['express_name'])){
            $where[] = ['express_name','like',"%".$cond['express_name']."%"];
        }

        if(!empty($cond['status'])){
            $where[] = ['status', '=',$cond['status']];
        }

        $rs = $this
            ->field($item)
            ->where($where)
            ->order($orderby)
            ->page($page, $limit)
            ->select()
            ->toArray();

        return $rs;
    }

    //新增、编辑(后台操作)
    function edit($params, $id=0){
        if($id>0){
            // 更新条件
            $where = ['express_id' => $id];
            $rs = $this->allowField(true)->save($params, $where);
        }else{
            // 更新数据
            $params['add_time'] = time();
            $rs = $this->save($params);
//            $rs = $this->address_id;
        }
        if ($rs === false) {
            $this->setError(-1, '操作失败');
            return false;
        }
        return $rs;
    }




}